<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="新增客户">
    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <style type="text/css">
        .layui-form-item .layui-word-aux{
            font-size: 12px;
            color: #FF5722;
        }

        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
    </style>
    <script>
        jQuery(function () {
            getByType("${baseUrl}",ORDER_TYPE.KH.type, $("[name='no']"));
            $(".reloadNo").click(function () {
                getByType("${baseUrl}",ORDER_TYPE.KH.type, $("[name='no']"),true);
            });

            ajaxSelect("${baseUrl}custom/customType/getAll.action","customTypeId");
            ajaxSelect("${baseUrl}user/user/getAll.action","userId",'无');
            ajaxSelect("${baseUrl}organization/store/getStores.action","storeId");

            $("#close").click(function () {
                closeSubIframe();
            });

            $("[name='name']").blur(function () {
                var name = $("[name='name']").val();
                if (name == null || name.length==0) {
                    $("#nameTip").html("名称不能为空");
                    return;
                }

                $("#nameTip").html("名称检测中");
                get("${baseUrl}custom/custom/checkName.action?name="+encodeURI(name),function (resp) {
                    if (resp.code == 1){
                        $("#nameTip").html(resp.msg);
                    } else if (resp.code == 2) {
                        $("#nameTip").html("");
                    } else {
                        $("#nameTip").html("未知异常");
                    }
                });
            });
            
            layui.use(['form', 'layedit', 'laydate','element'], function(){
                var form = layui.form
                    ,layer = layui.layer
                    ,layedit = layui.layedit
                    ,laydate = layui.laydate;

                //监听提交
                form.on('submit(save)', function(data){
                    if (data.field.name == "") {
                        tip("名称不能为空");
                        return false;
                    }
                    if (data.field.storeId == "") {
                        tip("门店不能为空");
                        return false;
                    }
                    if (data.field.customTypeId == "") {
                        tip("分类不能为空");
                        return false;
                    }
                    if (data.field.no == "") {
                        tip("编号不能为空，请点击重新获取");
                        return false;
                    }
                    if($("#nameTip").html() != ""){
                        return false;
                    }

                    if (data.field.def == undefined) {
                        data.field.def = false;
                    } else {
                        data.field.def = true;
                    }

                    console.log(JSON.stringify(data.field));
                    tipLoad("新增中,请稍后...");
                    post("${baseUrl}custom/custom/add.action",data.field,function (resp) {
                        closeAll();
                        if (resp.code == 1){
                            refreshMainIframe("${baseUrl}custom/custom.action");
                            closeSubIframe();
                        } else {
                            tip(resp.msg);
                        }
                    });
                    return false;
                });
            });
        });
    </script>
</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" method="post" action="" lay-filter="customData">
            <div style="padding: 14px 0 0 4px;font-size: 16px;">基本信息</div>
            <hr>
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="no" readonly="readonly" autocomplete="off"  class="layui-input readonly">
                </div>
                <div class="layui-input-inline" style="padding-top: 10px">
                    <a href="javascript:;" class="reloadNo">重新加载</a>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="请输入名称" autocomplete="off"  class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span id="nameTip" style="color: #FF5722;font-size: 12px;"></span></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">门店</label>
                <div class="layui-input-inline">
                    <select name="storeId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-inline">
                    <select name="customTypeId">
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-inline">
                    <input type="text" name="contacts" autocomplete="off"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="address" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">初期欠款</label>
                <div class="layui-input-inline">
                    <input type="number" name="initAmt" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">关联业务员</label>
                <div class="layui-input-inline">
                    <select name="userId">
                    </select>
                </div>
<%--                <div class="layui-form-mid layui-word-aux">选择“无”表示所有业务员都可以查看该客户；选择了客户关联的业务员后，该客户仅能被老板和业务员查看</div>--%>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">默认客户</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="def" lay-skin="switch" lay-filter="def" lay-text="是|否">
                </div>
            </div>


            <div style="padding: 14px 0 0 4px;font-size: 16px;">更多</div>
            <hr>
            <div class="layui-form-item">
                <label class="layui-form-label">微信号</label>
                <div class="layui-input-inline">
                    <input type="text" name="wechat" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">QQ</label>
                <div class="layui-input-inline">
                    <input type="text" name="qq" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">单位电话</label>
                <div class="layui-input-inline">
                    <input type="phone" name="unitTel" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">传真</label>
                <div class="layui-input-inline">
                    <input type="phone" name="tax" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                    <input type="email" name="email" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">邮编</label>
                <div class="layui-input-inline">
                    <input type="number" name="code" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="radio" name="status" value="1" title="启用" checked>
                    <input type="radio" name="status" value="2" title="停用">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" name="remark"></textarea>
                </div>
            </div>


            <div class="horizon-line" style="margin: 4px 0 4px 0"></div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
                    <a id="close" class="layui-btn layui-btn-primary" href="javascript:;">
                        取消
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<html:loading/>
</html>